package com.whity.towerdefense.controler;

import com.whity.towerdefense.controler.states.MainMenu;
import com.whity.towerdefense.model.GameModel;

import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;

public class GameControler implements OnClickListener, OnDrawerOpenListener, OnDrawerCloseListener, OnTouchListener
{
	// =============================================================
	// Private attributs :
	
	private static final String		TAG = "com.djm.test03.controler";
	
	private static I_State			m_CurrentState = null;
	
	// =============================================================
	// Public attributs :
	
	public static GameModel			GAME_MODEL;
	
	// =============================================================
	// Public functions :
	
	public GameControler(GameModel p_GameModel)
	{
		GAME_MODEL = p_GameModel;
		m_CurrentState = new MainMenu();
	}
	
	public static void SetState(I_State p_State)
	{
		//synchronized(m_CurrentState)
		//{
			m_CurrentState = p_State;
			m_CurrentState.OnChangeState();
			Log.i(TAG, "Change state : " + p_State.getClass().toString());
		//}
	}
	
	public void OnPause()
	{
		m_CurrentState.OnPause();
	}
	
	public void OnResume()
	{
		m_CurrentState.OnResume();
	}

	public void onClick(View p_View)
	{
		if(m_CurrentState != null)
		{
			//synchronized(m_CurrentState)
			//{
				m_CurrentState.OnClickEvent(p_View);
			//}
		}

	}

	public void onDrawerClosed()
	{
		if(m_CurrentState != null)
		{
			//synchronized(m_CurrentState)
			//{
				m_CurrentState.OnDrawerCloseEvent();
			//}
		}
	}

	public void onDrawerOpened()
	{
		if(m_CurrentState != null)
		{
			//synchronized(m_CurrentState)
			//{
				m_CurrentState.OnDrawerOpenEvent();
			//}
		}
	}

	public boolean onTouch(View p_View, MotionEvent p_Evt)
	{
		if(m_CurrentState != null)
		{
			return m_CurrentState.OnMotionEvent(p_View, p_Evt);
		}
		else
		{
			return false;
		}
	}
	
	// =============================================================
	
}
